<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="model.*,util.*"%>
<%@page import="bll.EnumName"%>
<%@page import="util.CacheUtil"%>
<%@page import="util.HtmlUtil"%>
<%
	AgendaItemModel obj;
	Object temp = request.getAttribute("agendaItem");
	if (temp != null) {
		try {
			obj = (AgendaItemModel) temp;
		} catch (Exception ex) {
			obj = new AgendaItemModel();
		}
	} else {
		obj = new AgendaItemModel();
	}
	int idAgenda = obj.getIdAgenda();
	
	AgendaModel agenda = CacheUtil.getAgenda(idAgenda);
	String agendaName = agenda.getName();
	String agendaUrl = "agenda.jsp?id=" + idAgenda;

	String projectName = CacheUtil.getProjectName(agenda.getIdProject());
	String projectUrl = "project.jsp?id=" + agenda.getIdProject();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Agenda Item</title>
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script language="javascript" type="text/javascript">
	$(document).ready(pageLoaded);
	
	function pageLoaded()
	{
		turnOnNumbericInput();
		initDateTimePicker();
		initTooltip();
<%-- 		<%  --%>
// 			if (obj.getIsGroup())
// 			{
// 		%>
// 				toggleControls(['row_description', 'row_id_parent', 'row_id_prev_item', 
// 								'row_sound', 'row_light', 'row_left_screen', 'row_right_screen', 'row_center_screen', 
// 								'row_remark', 'row_id_employee', 'row_id_company', 'row_status']);
// 				toggleHyjackControl(['id_employee', 'id_company']);
<%-- 		<% --%>
// 			}
// 		%>
	}
	
	var requiredInputs = [['name','name_required'],['start_time_date','start_time_date_required'],['duration','duration_required']];
// 	var intInputs = [];
// 	var doubleInputs = [];
// 	var dateInputs = [];
	var timeInputs = [['start_time_date','start_time_date_invalid']];

	function checkInputs() {
		var valid = true;

		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
// 		if (checkIntInputs(intInputs) == false) {
// 			valid = false;
// 		}
// 		if (checkDoubleInputs(doubleInputs) == false) {
// 			valid = false;
// 		}
// 		if (checkDateInputs(dateInputs, dateFormat) == false) {
// 			valid = false;
// 		}
		if (checkTimeInputsForCorrectFormatOnly(timeInputs) == false) {
			valid = false;
		}

		// SPECIFIC VALIDATE CODE HERE		

		return valid;
	}
</script>
</head>
<body>
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
				<form id="inputForm" action="agendaItem?mode=update&id_agenda=<%=idAgenda %>" method="post" onSubmit="return checkInputs()" onreset="return confirm('Do you really want to reset the form?')">
					<table class="tblInput">
						<tr>
							<td colspan="1">
								<b>Project: <a id="link_project" name="link_project" href="<%=projectUrl %>"><%=projectName %></a></b>
								<br />&gt;
								<b>Agenda: <a id="link_quotation" name="link_quotation" href="<%=agendaUrl %>"><%=agendaName %></a></b>
							</td>
						</tr>
					
						<tr >
							<td class="inputHeader">EDIT AGENDA ITEM</td>
						</tr>
						<tr>
					<td style="padding-left: 200px; padding-right: 200px;">
						<table cellspacing="0px">
						<tr class="trField">
							<td class="tdFieldName">Id</td>
							<td class="tdFieldInput"><input class="inputInt readonly" type="text" id="id" name="id" readonly="readonly" value="<%=obj.getIdToString()%>" title="Id of agenda item. It's readonly."/></td>
							<td class="tdErrMsg"></td>
							<td rowspan="7" style="width: 30px;"></td>
							
							<td class="tdFieldName">Sound</td>
							<td class="tdFieldInput"><textarea id="sound" name="sound" title="Sound" rows="5" class="inputTextarea" tabindex="9"><%=obj.getSound()%></textarea>
							</td>
							<td class="tdErrMsg"></td>						
						</tr>

						<tr class="trField">
							<td class="tdFieldName">Name</td>
							<td class="tdFieldInput"><input class="inputText" title="Name of this agenda item." type="text" id="name" name="name" maxlength="255" value="<%=obj.getName()%>" tabindex="1" onblur="validateRequiredInput('name');"/>
							</td>
							<td class="tdErrMsg">
								<span id="name_required" class="errMsg" style="display: none;" title="Agenda item name is a required field." title="">(!)</span> 
								<span id="name_invalid" class="errMsg" style="display: none;" title="invalid agenda item name">(!)</span> 
								<span id="name_error" class="errMsg"><%=obj.errMsgs.Name%></span>
							</td>

							<td class="tdFieldName">Light</td>
							<td class="tdFieldInput"><textarea id="light" name="light" title="Light" rows="5" class="inputTextarea" tabindex="10"><%=obj.getLight()%></textarea>
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Description</td>
							<td class="tdFieldInput"><textarea id="description" title="Description for this agenda" name="description" rows="5" class="inputTextarea" tabindex="2"><%=obj.getDescription()%></textarea></td>
							<td class="tdErrMsg"></td>
						
							<td class="tdFieldName">Left Screen</td>
							<td class="tdFieldInput"><textarea id="left_screen" title="Left screen" name="left_screen" rows="5" class="inputTextarea" tabindex="11"><%=obj.getLeftScreen()%></textarea></td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Start Time</td>
							<td class="tdFieldInput"><input type="text" maxlength="19" class="inputDateTime" id="start_time_date" name="start_time_date" value="<%=StringUtil.toVisualDateTimeString(obj.getStartTime())%>" title="Click to choose start time.<br/>Note: the format is <b>dd/mm/yyyy at hh:mm</b>.<br/>Note: Required." tabindex="1" onblur="validateRequiredInput('start_time_date',true);" onchange="validateDateTimeInput('start_time_date', true);"/> <!-- 								<table class="tblDateTime"> --> <!-- 									<tr class="trDateTime"> --> <!-- 										<td class="tdDate"><input type="text" maxlength="10" --> <!-- 											class="inputDate" id="start_time_date" name="start_time_date" --> <%-- 											value="<%=DateTimeUtil.getDayString(obj.getStartTime())%>" /> --%> <!-- 											<input type="button" class="btnCalendar" value="..." --> <!-- 											onclick="javascript:displayDatePicker('start_time_date', this, dateFormat);" /> --> <!-- 										</td> --> <!-- 										<td class="tdTime"><input type="text" maxlength="5" --> <!-- 											class="inputTime" id="start_time_time" name="start_time_time" --> <%-- 											value="<%=DateTimeUtil.getTimeString(obj.getStartTime())%>" /> --%>
								
							<td class="tdErrMsg">
								<span id="start_time_date_required" class="errMsg" style="display: none;" title="Start time is a required field.">(!)</span>
								<span id="start_time_date_invalid" class="errMsg" style="display: none;" title="You've entered an invalid time.<br/>The format should be <b> 'dd/mm/yyyy at hh/mm'</b>">(!)</span>
								<span id="start_time_error" class="errMsg"><%=obj.errMsgs.StartTime%></span>
							</td>
							
							<td class="tdFieldName">Right Screen</td>
							<td class="tdFieldInput"><textarea id="right_screen" title="Right screen" name="right_screen" rows="5" class="inputTextarea" tabindex="12"><%=obj.getRightScreen()%></textarea></td>
							<td class="tdErrMsg"></td>
						</tr>
						
						<tr id="row_description" class="trField">
							<td class="tdFieldName">Duration</td>
							<td class="tdFieldInput"><input class="inputInt" type="text" title="Duration of this agenda item in minute.<br/>Note: only integer allowed." id="duration" name="duration" maxlength="10" value="<%=obj.getDurationToString()%>" tabindex="4"  onblur="validateRequiredInput('duration');"/> minute(s)</td>
							<td class="tdErrMsg">
								<span id="duration_required" class="errMsg" style="display: none;" title="Duration is a required field.">(!)</span> 
								<span id="duration_invalid" class="errMsg" style="display: none;" title="You've entered an invalid duration.">(!)</span> 
								<span id="duration_error" class="errMsg" title="<%=obj.errMsgs.Duration%>"></span></td>
							
							<td class="tdFieldName">Center Screen</td>
							<td class="tdFieldInput"><textarea id="center_screen" title="Center screen" name="center_screen" rows="5" class="inputTextarea" tabindex="13"><%=obj.getCenterScreen()%></textarea></td>
							<td class="tdErrMsg"></td>
						</tr>
						
						<tr id="row_id_employee" class="trField">
							<td class="tdFieldName">Employee<br />in charge</td>
							<td class="tdFieldInput"><select id="id_employee" name="id_employee" class="hyjack" tabindex="5">
									<%=HtmlUtil.genModelSelect(CacheUtil.getEmployeeList(), null, obj.getIdEmployee(), false, true)%>
							</select> <input class="btnAdd" type="button" id="addNewIdCompany" value="" onclick="ajaxAddItem('#id_employee', 'employee', 'name', 'Please enter new employee name!');" title="Click to add new employee" tabindex="6"/>
							</td>
							
							<td class="tdErrMsg"></td>
							<td class="tdFieldName">Remark</td>
							<td class="tdFieldInput"><textarea id="remark" name="remark" title="Remark" rows="5" class="inputTextarea" tabindex="14"><%=obj.getRemark()%></textarea></td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr id="row_id_company" class="trField">
							<td class="tdFieldName">Company<br />in charge</td>
							<td class="tdFieldInput"><select id="id_company" name="id_company" class="hyjack" tabindex="7">
									<%=HtmlUtil.<CompanyModel>genModelSelect(CacheUtil.getCompanyList(), null, obj.getIdCompany(), false, true)%>
							</select> <input class="btnAdd" type="button" id="addNewIdCompany" value="" onclick="ajaxAddItem('#id_company', 'company', 'short_name', 'Please enter your company short name!');" title="Click to add new company" tabindex="8"/>
							</td>
							<td class="tdErrMsg"></td>
						
							<td class="tdFieldName">Status</td>
							<td class="tdFieldInput"><select id="status" name="status" title="Click to choose one status" class="hyjack" tabindex="15">
									<%=HtmlUtil.genEnumSelect(EnumName.AgendaItemStatus, null,
					obj.getStatus())%>
							</select></td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trInputBottom">
							<td class="tdInputBottom" colspan="7"><input class="btnSubmit" type="submit" value="Submit" tabindex="14" title="Click to save."/></td>
						</tr>
<!-- 						<tr class="trInputBottom"> -->
<!-- 							<td class="tdInputBottom" colspan="6"> -->
<!-- 								<table class="tblSubmit" align="center"> -->
<!-- 									<tr class="trSubmit"> -->
<!-- 										<td class="tdSubmit"><input class="btnSubmit" type="submit" value="Submit" title="Click to save changes" tabindex="16"/></td> -->
<!-- 									</tr> -->
<!-- 								</table></td> -->
<!-- 						</tr> -->
						</table>
				</td>
			</tr>
		</table>
	</form>
	<%
		//String str = "agendaItemList.jsp?embedded=true&idAgenda=" + obj.getIdAgenda();
		String str = "agenda.jsp?embedded=true&id=" + obj.getIdAgenda();
	%>
	<jsp:include page="<%=str%>"></jsp:include>
	</div>
</body>
</html>